<?php

namespace IDock\Insurance\JDAL\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\JDAL\JDALEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends AllJDALResponse
{

    /**
     * @var VehicleModelPrinter $printer
     */
    public $printer = VehicleModelPrinter::class;

    public function printerInit(): Response
    {
        $data = $this->getBody();

        $orderId = $data['orderId'] ?? '';

        foreach ($data['vehicleList'] ?? [] as $item) {
            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = ($item['modelCode'] ?? '') . '-' . ($item['vehicleStyleUniqueId'] ?? '');
            $vehiclePrinter->vehicleTonnage = $item['tonnage'] ?? '';
            $vehiclePrinter->vehicleExhaust = (string)(($item['displacement'] ?? '') ? $item['displacement'] / 1000 : '');
            $vehiclePrinter->vehicleSeat = $item['seatingCapacity'] ?? '';
            $vehiclePrinter->power = '';
            $vehiclePrinter->remark = $item['remark'] ?? '';
            $vehiclePrinter->vehicleName = $item['carName'] ?? '';
            $vehiclePrinter->brandName = $item['make'] ?? '';

            $vehiclePrinter->vehiclePriceWithOutTax = $item['vehiclePrice'] ?? '';
            $vehiclePrinter->vehiclePrice = $item['newCarValue'] ?? '';
            $vehiclePrinter->wholeWeight = $item['wholeWeight'] ?? '';

            $vehiclePrinter->vehicleYear = $item['modelOfYear'] ?? '';

            $vehiclePrinter->energyTypeCode = JDALEnums::$energyType1[$item['fuelType'] ?? ''];
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode];
            $vehiclePrinter->isNewEnergy = '';

            $modelEnergyType = $item['modelEnergyType'] ?? '';

            if ($modelEnergyType == '1' or $modelEnergyType == '3') {
                $vehiclePrinter->isNewEnergy = true;
            }

            $vehiclePrinter->vehicleTypeCode = $item['vehicleCode'] ?? '';

            $vehiclePrinter->item = $item;
            $vehiclePrinter->item['orderId'] = $orderId;

            $this->printer->setModelList($vehiclePrinter);
        }

        return $this;
    }
}
